package com.daoImpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.dao.EmployeeDao;
import com.model.Employee;

@Component("employeeDao")
public class EmployeeDaoImpl implements EmployeeDao {

	public Employee getEmployee(String em_serialNumber) {
		return (Employee)this.hibenrateTemplate.get(Employee.class,em_serialNumber);
	}

	public List<Employee> getEmployeeList(String hql) {
		List<Employee> list= this.hibenrateTemplate.find(hql);
		return list;
	}
	private HibernateTemplate hibenrateTemplate;
	
	
	public void addEmployee(Employee employee) {
		hibenrateTemplate.save(employee);
	}

	public void deleteEmployee(Employee employee) {
		hibenrateTemplate.delete(employee);
	}

	public boolean exists(Employee employee) {
		List list=hibenrateTemplate.find("from Employee e where e.em_serialNumber='"+employee.getEm_serialNumber()+"' ");
		if(list!=null&&list.size()>0){
			return true;
		}
		else return false;
	}

	public void updateEmployee(Employee employee) {
		hibenrateTemplate.update(employee);
	}

	public HibernateTemplate getHibenrateTemplate() {
		return hibenrateTemplate;
	}
	@Resource
	public void setHibenrateTemplate(HibernateTemplate hibenrateTemplate) {
		this.hibenrateTemplate = hibenrateTemplate;
	}

}
